package cn.wolfcode.crud.service.impl;

import cn.wolfcode.crud.domain.Department;
import cn.wolfcode.crud.mapper.DepartmentMapper;
import cn.wolfcode.crud.qo.PageResult;
import cn.wolfcode.crud.qo.QueryObject;
import cn.wolfcode.crud.service.IDepartmentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

@Service
@Transactional
public class DepartmentServiceImpl implements IDepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;


    public void save(Department department) {
        departmentMapper.save(department);
    }

    public void delete(Long id) {
        departmentMapper.delete(id);
    }

    public void update(Department department) {
        departmentMapper.update(department);
    }

    @Transactional(readOnly = true)
    public Department get(Long id) {
        Department department= departmentMapper.get(id);
        return department;
    }

    @Transactional(readOnly = true)
    public List<Department> listAll() {
        List<Department> department = departmentMapper.listAll();
        return department;
    }

    @Override
    public PageInfo<Department> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
       List<Department> departments = departmentMapper.selectForList(qo);
        return new PageInfo<Department>(departments);
    }
}
